#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <gtest/gtest.h>
#include <libgo/coroutine.h>
#include <boost/progress.hpp>

#define O(x) std::cout << x << std::endl

namespace thread {
    std::atomic_int g_value{ 0 };
    static const int co_count = 100000;
    static const int switch_per_co = 10;

    void f1() {
        for (int i = 0; i < switch_per_co; ++i) {
            g_value++;
            co_yield;
        }
    }
}

TEST(thread, test) {
    using namespace thread;

    for (int i = 0; i < co_count; ++i) {
        go f1;
    }

    O("go");
    {
        boost::progress_timer pt;
        co_sched.Start();
        O("main thread, run " << co_count << " coroutines, " << co_count * switch_per_co  << " times switch. cost " << g_value << "nend");
    }
}

